package com.ray.friendslist;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
//import android.view.KeyEvent;
import android.view.Menu;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.ray.friendslist.api.VkLoginRequest;

public class MainActivity extends Activity{

	private Intent intent;
	private ProgressBar mProgressBar;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mProgressBar=(ProgressBar)findViewById(R.id.progressBar);
        new Thread(new Runnable() {
			
			public void run() {
				// TODO Auto-generated method stub
				mProgressBar.setVisibility(ProgressBar.VISIBLE);
			}
		}).start();
        try{
        if(VkLoginRequest.isAuthorised()){
        	intent=new Intent(this,VkFriendsListActivity.class);
        }
        else{
        	intent=new Intent(this,VkLoginActivity.class);
        }
        mProgressBar.setVisibility(ProgressBar.GONE);
        startActivity(intent);
        finish();
        }
        catch(Exception e)
        {
        	Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        	Log.e("ray", e.getMessage());
        }
    }
        
        @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
  
}      